# -*- coding: utf-8 -*-
# @File: loader_yaml.py


import yaml
import os
from pathlib import Path


class LoaderYaml:
    """YAML 测试数据加载器"""

    def __init__(self, file_path=r"test_case\data\test_data.yaml"):
        self.base_path = Path(__file__).resolve().parent.parent
        self.file_path = os.path.join(self.base_path, file_path)
        print(self.file_path)


    def read_yaml(self):
        """加载测试数据"""
        try:
            with open(self.file_path, 'r', encoding='utf-8') as f:
                data = yaml.safe_load(f)
                return data
            #     return {
            #     "login_cases": data.get("login_cases", []),
            #     "logout_cases": data.get("logout_cases", [])
            # }
        except FileNotFoundError:
            raise Exception(f"测试数据文件未找到: {self.file_path}")
        except yaml.YAMLError as e:
            raise Exception(f"YAML 解析错误: {str(e)}")
        except Exception as e:
            raise Exception(f"加载测试数据失败: {str(e)}")


# 使用示例
if __name__ == "__main__":
    loader_yaml = LoaderYaml()
    test_data = loader_yaml.read_yaml()
    print(type(test_data))
    print("所有登录测试用例:", test_data)



